from lxml import etree

xml = """<?xml version="1.0" encoding="utf8"?>
<bookstore>
	<book>
		<title lang="eng">Harry Potter</title>
		<price>29.99</price>
	</book>
	<book>
		<title lang="eng">Learning XML</title>
		<price>39.95</price>
	</book>
</bookstore>"""


def xpath_test():
    root = etree.fromstring(xml.encode('utf-8'))
    print("root:", root.tag)
    books = root.xpath('book')
    for book in books:
        elems = book.getchildren()
        for ele in elems:
            print(ele.text, end=',')
        print()


if __name__ == '__main__':
    xpath_test()
